package net.whg.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.extern.slf4j.Slf4j;
import net.whg.mapper.TrafficMapper;
import net.whg.model.TrafficDO;
import net.whg.service.TrafficService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Random;

@Service
@Slf4j
public class TrafficServiceImpl implements TrafficService {

    @Resource
    private TrafficMapper trafficMapper;

    @Override
    @DS("master")
    public void save() {
        Random random = new Random();
        TrafficDO trafficDO = TrafficDO.builder()
                .dayLimit(random.nextInt(100))
                .dayUsed(random.nextInt(100))
                .totalLimit(random.nextInt(100))
                .accountNo(random.nextLong())
                .outTradeNo("outTradeNo" + random.nextInt(100))
                .level("level" + random.nextInt(100))
                .expiredDate(new java.util.Date())
                .pluginType("pluginType" +random.nextInt(100)).build();
        trafficMapper.insert(trafficDO);
    }


    @Override
    @DS("master")
    public List<TrafficDO> list1() {
        return trafficMapper.selectList(null);
    }

    @Override
    @DS("slave")
    public List<TrafficDO> list2() {
        return trafficMapper.selectList(null);
    }
}
